package com.example.project.webControlleer;

import com.example.project.dao.CarDAO;
import com.example.project.pojo.Car;
import com.example.project.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;

//@MultipartConfig
//@WebServlet("/UpdateCarController")
//public class WebChangeCarController extends HttpServlet {
//        @Override
//        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//            this.doPost(request, response);
//        }
//
//        @Override
//        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//            String license = request.getParameter("license");
//            String sid = request.getParameter("id");
//
//
//            Car car = new Car();
//            car.setLicense(license);
//            car.setId(Integer.parseInt(sid));
//
//            CarDAO carDAO=new CarDAO();
//            carDAO.changeUser(car);
//
//            response.sendRedirect("/project/checkcar");
//        }
//    }

@Controller
@RequestMapping("web")
public class WebChangeCarController {

    @RequestMapping("updatecar")
    public String addcar(HttpServletRequest request) {
       Integer id= Integer.parseInt(request.getParameter("id"));
       CarDAO carDAO =new CarDAO();
      Car car = carDAO.findCarByID(id);
       request.setAttribute("car",car);
        return "web/changecar";
    }

    @RequestMapping("updateCarMess")
    public String updateCarMess(Car car, HttpSession session) {
       User user= (User) session.getAttribute("user");
       car.setUser(user);
        CarDAO carDAO=new CarDAO();
        carDAO.updateCarLicense(car);



        return "redirect:/web/checkcar";
    }
}


